Static library support improvements (#123)
authorpast-due <30942300+past-due@users.noreply.github.com>
Mon, 30 Apr 2018 01:37:12 +0000 (21:37 -0400)
committerSteven G. Johnson <stevenj@mit.edu>
Mon, 30 Apr 2018 01:37:12 +0000 (21:37 -0400)
* `#define UTF8PROC_STATIC` to disable DLLEXPORT

`#define UTF8PROC_STATIC` to disable DLLEXPORT

* [CMake] Automatically define UTF8PROC_STATIC if BUILD_SHARED_LIBS is off

* [Makefile] Support additional UTF8PROC_DEFINES, which can be used to specify flags like `-DUTF8PROC_STATIC`

CMakeLists.txt
Makefile
utf8proc.h

index cbc8d93ca01727a20241d104f3a6a816d2de6aa6..d07dee13bc71453030872164dd30da794d5a0dc2 100644 (file)
@@ -22,6 +22,13 @@ add_library (utf8proc
   utf8proc.h
 )
 
+if (BUILD_SHARED_LIBS)
+  # Building shared library
+else()
+  # Building static library
+  target_compile_definitions(utf8proc PUBLIC "UTF8PROC_STATIC")
+endif()
+
 target_compile_definitions(utf8proc PRIVATE "UTF8PROC_EXPORTS")
 
 set_target_properties (utf8proc PROPERTIES
index f8e5e8b210ec5d878d78654d68d65e216565fe6c..5efd7e817fd299d52d92ab41b1f47eb82d3ad2b8 100644 (file)
--- a/Makefile
+++ b/Makefile
@@ -11,7 +11,7 @@ CFLAGS ?= -O2
 PICFLAG = -fPIC
 C99FLAG = -std=c99
 WCFLAGS = -Wall -pedantic
-UCFLAGS = $(CFLAGS) $(PICFLAG) $(C99FLAG) $(WCFLAGS) -DUTF8PROC_EXPORTS
+UCFLAGS = $(CFLAGS) $(PICFLAG) $(C99FLAG) $(WCFLAGS) -DUTF8PROC_EXPORTS $(UTF8PROC_DEFINES)
 
 # shared-library version MAJOR.MINOR.PATCH ... this may be *different*
 # from the utf8proc version number because it indicates ABI compatibility,
index 7b3e6fde90b0ea227c240d69045a8cb102175996..912985366d3cfe2e7928c90c78e36df716047f54 100644 (file)
@@ -120,16 +120,20 @@ typedef bool utf8proc_bool;
 #endif
 #include <limits.h>
 
-#ifdef _WIN32
-#  ifdef UTF8PROC_EXPORTS
-#    define UTF8PROC_DLLEXPORT __declspec(dllexport)
+#ifdef UTF8PROC_STATIC
+#  define UTF8PROC_DLLEXPORT
+#else
+#  ifdef _WIN32
+#    ifdef UTF8PROC_EXPORTS
+#      define UTF8PROC_DLLEXPORT __declspec(dllexport)
+#    else
+#      define UTF8PROC_DLLEXPORT __declspec(dllimport)
+#    endif
+#  elif __GNUC__ >= 4
+#    define UTF8PROC_DLLEXPORT __attribute__ ((visibility("default")))
 #  else
-#    define UTF8PROC_DLLEXPORT __declspec(dllimport)
+#    define UTF8PROC_DLLEXPORT
 #  endif
-#elif __GNUC__ >= 4
-#  define UTF8PROC_DLLEXPORT __attribute__ ((visibility("default")))
-#else
-#  define UTF8PROC_DLLEXPORT
 #endif
 
 #ifdef __cplusplus